Stored Procedures [dbo].[BAEGetPrefixLabels]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
SQL Script
CREATE PROCEDURE [dbo].[BAEGetPrefixLabels]
AS
    DECLARE @prefixDescription varchar(255)
    DECLARE @prefix table(code varchar(60), description varchar(255))

    DECLARE PrefixCursor CURSOR    -- Declare the cursor and get all of the distinct description values
    READ_ONLY
    FOR
    SELECT DISTINCT DESCRIPTION
    FROM Gen_Tables
    WHERE TABLE_NAME = 'PREFIX' AND (LEN(RTRIM(LTRIM(DESCRIPTION))) > 0)

    OPEN     PrefixCursor    -- Open the cursor

    FETCH NEXT FROM PrefixCursor INTO @prefixDescription
    WHILE (@@fetch_status <> -1)    -- Loop through results
    BEGIN
        
        -- Select the first code in the table based on the description and store that in the table variable @suffix
        INSERT INTO @prefix(code, description)
        SELECT TOP 1 CODE, @prefixDescription
        FROM Gen_Tables g
        WHERE TABLE_NAME = 'PREFIX' and DESCRIPTION = @prefixDescription


        FETCH NEXT FROM PrefixCursor INTO @prefixDescription    --Get the next record/description
    END

    -- get rid of the cursor
    CLOSE PrefixCursor
    DEALLOCATE PrefixCursor

    -- Return all of the values from the suffix table variable which will include distinct descriptions and the associated codes
    SELECT * FROM @prefix


---------------------------------------
---------------------------------------
-- FIX FOR ORDER CATEGORIES.         --
--                                   --
-- THERE MUST BE A CATEGORY WITH THE --
-- ID OF 1                           --
---------------------------------------
---------------------------------------

SET IDENTITY_INSERT [dbo].[OrderCategory] ON

GO
Uses